package com.example.john.ksoap2test001;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by john on 16/4/17.
 */
public class MyAdapter extends BaseAdapter {
    private List<Food> foods;
    private LayoutInflater inflater;

    public MyAdapter(List<Food> foods, LayoutInflater inflater) {
        this.foods = foods;
        this.inflater = inflater;
    }

    @Override
    public int getCount() {
        return foods.size();
    }

    @Override
    public Object getItem(int position) {
        return foods.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    //渲染
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        convertView=inflater.inflate(R.layout.pro,null);
        ImageView snap=(ImageView)convertView.findViewById(R.id.snap);
        TextView title=(TextView)convertView.findViewById(R.id.Tit);
        TextView content=(TextView)convertView.findViewById(R.id.content);
        title.setText(foods.get(position).getTitle());
        content.setText(foods.get(position).getContent());

        snap.setImageResource(foods.get(position).getSnap());
        snap.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i("john",foods.get(position).getTitle());
            }
        });

        return convertView;
    }
}
